public class MyQueue {
    static class ListNode {
        private int val;
        private ListNode prev;
        private ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    private int usedSize = 0;
    private ListNode front;
    private ListNode rear;
    
    public void offer(int data) {
        ListNode node = new ListNode(data);
        if (front == null) {
            front = rear = node;
        }else {
            front.prev = node;
            node.next = front;
            front = node;
        }
        usedSize++;
    }
    public int poll() {
        if (front == null) {
            return -1;
        }else if (front == rear) {
            int ret = rear.val;
            front = rear = null;
            usedSize--;
            return ret;
        }else {
            int ret = rear.val;
            rear = rear.prev;
            rear.next = null;
            usedSize--;
            return ret;
        }
    }
    public int peek () {
        if (isEmpty()){
            return -1;
        }
        return front.val;
    }
    public int getUsedSize () {
        return usedSize;
    }
    public boolean isEmpty(){
        return usedSize == 0;
    }
}
